/*
 * @Author: LVGRAPE
 * @LastEditors: LVGRAPE
 */
#ifndef __ZINO_H__
#define __ZINO_H__

#include <stdbool.h>
#include <stdint.h>
#include <string.h>

#include "delay.h"
#include "uart.h"
#include "zino_pin.h"
#include "pwr.h"
#include "zino_shell.h"
#include "os_timer.h"

typedef int (*init_fn_t)(void);
#define RT_USED                     __attribute__((used))
#define RT_SECTION(x)               __attribute__((section(x)))

#define ZINO_EXPORT(fn, level)                                                       \
            RT_USED const init_fn_t __zino_init_##fn RT_SECTION(".zino_init_fn." level) = fn
/* board init routines will be called in board_init() function */
#define ZINO_BOARD_EXPORT(fn)           ZINO_EXPORT(fn, "1")

/* pre/device/component/env/app init routines will be called in init_thread */
/* components pre-initialization (pure software initialization) */
#define ZINO_PREV_EXPORT(fn)            ZINO_EXPORT(fn, "2")
/* device initialization */
#define ZINO_DEVICE_EXPORT(fn)          ZINO_EXPORT(fn, "3")
/* components initialization (dfs, lwip, ...) */
#define ZINO_COMPONENT_EXPORT(fn)       ZINO_EXPORT(fn, "4")
/* environment initialization (mount disk, ...) */
#define ZINO_ENV_EXPORT(fn)             ZINO_EXPORT(fn, "5")
/* application initialization (rtgui application etc ...) */
#define ZINO_APP_EXPORT(fn)             ZINO_EXPORT(fn, "6")

#define ZINO_ASSERT(expr)                                                            \
    if(!(expr)) rt_kprintf("ASSERT ERROR! %s, %d, %s\n", __FILE__, __LINE__, #expr)
int zino_board_init();
int zino_components_init();

#endif
